﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GcmpDatabase.h"
#include "NdbObjectUnserializeResult.h"
#include "GcmpApiDeclaration.h"

namespace gcmp
{
    class IDbObject;
    class NdbObject;
    class NdbObjectMemoryModelNode;

    /// \brief 【内部使用，请勿调用】NdbObject打包助手工具
    class GCMP_DATABASE_EXPORT NdbObjectArchiveHelper
    {
    public:
        /// \brief 【内部使用】从对象模型中创建Ndb对象
        /// \param[in]     opMemoryModel          对象模型
        /// \param[out]    unSerializeResult      创建结果
        /// \return        OwnerPtr<NdbObject>    创建出的对象
        static OwnerPtr<NdbObject> CreateObjectFromMemoryModel(
            OwnerPtr<NdbObjectMemoryModelNode> opMemoryModel,
            NdbObjectUnserializeResult & unSerializeResult,
            UInt32 majorVersion = 1
        );

        static OwnerPtr<NdbObject> CreateOwnedNdbObjectFromMemoryModel(NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion = 1);
        
        /// \brief 从对象模型中创建IDbObject对象
        /// \param[in]     pObjMemModel           对象模型
        /// \param[out]    result                 创建结果
        /// \param[in]     rootNodeIsOwnerPtr     对象模型中的根节点是否为OwnerPtr，默认是
        /// \return        OwnerPtr<IDbObject>    创建出的对象
        static OwnerPtr<IDbObject> CreateOwnedIDbObjectFromMemoryModel(
            NdbObjectMemoryModelNode * pObjMemModel,
            NdbObjectUnserializeResult & result,
            bool rootNodeIsOwnerPtr = true,
            UInt32 majorVersion = 1
        );
        
        static NdbObjectUnserializeResult GetObjectFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel,  bool isParentSubObject, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetValueFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel);
        static NdbObjectUnserializeResult GetSchematicObjectFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, bool isParentSubObject, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetCloneableObjectFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetOwnerPtrFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetOwnerPtrToIDbObjectFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetPointerFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel);
        static NdbObjectUnserializeResult GetElementIdFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel);
        static NdbObjectUnserializeResult GetWStringFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel);
        static NdbObjectUnserializeResult GetVectorFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetSetFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetMapFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
        static NdbObjectUnserializeResult GetUnorderMapFromMemoryModel(void * pStartAddr, NdbObjectMemoryModelNode * pObjMemModel, UInt32 majorVersion);
    };
}
